package com.lingyun.financialmanagement.controller;

import com.lingyun.financialmanagement.dao.pojo.*;
import com.lingyun.financialmanagement.service.*;
import com.lingyun.financialmanagement.service.pojo.CompanyServiceImpl;
import com.lingyun.financialmanagement.vo.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.support.HttpRequestHandlerServlet;

@RestController
@RequestMapping("public")
public class PublicController {

    @Autowired
    private BillService billService;

    @Autowired
    private BusinessTripService businessTripService;

    @Autowired
    private ProjectService projectService;

    @Autowired
    private ComponentPartService componentPartService;

    @Autowired
    private OperationLogService operationLogService;

    @Autowired
    private UserService userService;

    @Autowired
    private ExcelService excelService;

    @Autowired
    private CompanyService companyService;

    @Autowired
    private HttpServletRequest request;


    //~~~~~~~~所有的公共的接口~~~~~~~~

    // ~~~~~~~~~~~~~~项目~~~~~~~~~~~~~~

    // 项目 查询所有项目
    @GetMapping("selectAllProject")
    public Result selectAllProject(){
        return projectService.selectAllProject();
    }

    // 项目 获取所有项目与仓库
    @GetMapping("selectAllProjectAndWarehouse")
    public Result selectAllProjectAndWarehouse(){
        return projectService.selectAllProjectAndWarehouse();
    }

    // 项目 通过id查询项目
    @GetMapping("selectProjectById")
    public Result selectProjectById(@RequestParam Integer id){
        return projectService.selectProjectById(id);
    }

    // 仓库 查询仓库
    @GetMapping("selectWarehouse")
    public Result selectWarehouse(){
        return projectService.selectWarehouse();
    }

    // 项目 推荐 通过用户token推荐用户常用项目
    @GetMapping("recommendProjectToken")
    public Result recommendProjectToken(){
        return projectService.recommendProjectToken();
    }

    // 增加项目
    @PostMapping("addProject")
    public Result addProject(@RequestBody Project project){
        return projectService.addProject(project);
    }

    // 项目付款 type: 1: 公户收款  2：现金收款
    @PostMapping("addProjectWareHouse")
    public Result addProjectWareHouse(@RequestParam Integer id, @RequestParam Integer type, @RequestParam Float cost){
        return projectService.addProjectWareHouse(id, type, cost);
    }

    // 项目 修改状态
    @PostMapping("updateStateProject")
    public Result updateStateProject(@RequestParam Integer id, @RequestParam String state){
        return projectService.updateStateProject(id, state);
    }

    // 项目 删除项目 （项目需为空）
    @DeleteMapping("deleteProjectById")
    public Result deleteProjectById(@RequestParam Integer id){
        return projectService.deleteProjectById(id);
    }


    // ~~~~~~~~~~~~元器件~~~~~~~~~~~~~~~

    // 元器件 查询所有
    @GetMapping("selectAllComponent")
    public Result selectAllComponent(){
        return componentPartService.selectAllComponent();
    }

    // 元器件 通过id查询
    @GetMapping("selectComponentById")
    public Result selectComponentById(@RequestParam Integer id){
        return componentPartService.selectComponentById(id);
    }

    // 元器件 通过项目或仓库ID去查询 元器件
    @GetMapping("selectByProjectToComponent")
    public Result selectByProjectToComponent(@RequestParam Integer projectId){
        return componentPartService.selectByProjectToComponent(projectId);
    }

    // 元器件 查看所有未结清的账单
    @GetMapping("selectAllPayMethodComponent")
    public Result selectAllPayMethodComponent(){
        return componentPartService.selectAllPayMethodComponent();
    }

    // 元器件 通过token获取未结清账单
    @GetMapping("selectPayMethodComponentToken")
    public Result selectPayMethodComponentToken(){
        return componentPartService.selectPayMethodComponentToken();
    }

    // 元器件 添加元器件
    @PostMapping("addComponentPart")
    public Result addComponentPart(@RequestBody ComponentPart componentPart){
        return componentPartService.addComponentPart(componentPart);
    }

    // 元器件 出库   去任何仓库都不会带走税额
    @PostMapping("outPutComponentPart")
    public Result outPutComponentPart(@RequestParam Integer id, @RequestParam Integer number, @RequestParam Integer project){
        return componentPartService.outPutComponentPart(id, number, project);
    }

    // 元器件 搜索    搜索仓库元件通过名字
    @GetMapping("selectWarehouseName")
    public Result selectWarehouseName(@RequestParam String name){
        return componentPartService.selectWarehouseName(name);
    }

    // 元器件 搜索    搜索仓库元件通过编号
    @GetMapping("selectWarehouseNumber")
    public Result selectWarehouseNumber(@RequestParam String serialNumber){
        return componentPartService.selectWarehouseNumber(serialNumber);
    }

    // 元器件  查找付款方式为赊销的所有元器件
    @GetMapping("selectCreditComponent")
    public Result selectCreditComponent(){
        return componentPartService.selectCreditComponent();
    }

    // 元器件  撤销删除
    @PostMapping("revocationComponentState")
    public Result revocationComponentState(@RequestParam Integer id){
        return componentPartService.revocationComponentState(id);
    }

    // ~~~~~~~~~~~~出差~~~~~~~~~~~~~~~
    // 增加差旅表单
    @PostMapping("addBusinessTrip")
    public Result addBusinessTrip(@RequestBody BusinessTrip businessTrip){
        return componentPartService.addBusinessTrip(businessTrip);
    }

    // ~~~~~~~~~~~~出差~~~~~~~~~~~~~~~

    /*// 出差 通过token查询自己的出差记录
    @GetMapping("selectByTokenBusinessTrip")
    public Result selectByTokenBusinessTrip(){
        return businessTripService.selectByTokenBusinessTrip();
    }

    // 出差 查询所有出差记录
    @GetMapping("selectAllBusinessTrip")
    public Result selectAllBusinessTrip(){
        return businessTripService.selectAllBusinessTrip();
    }

    // 出差 查看 所有未结清的账单
    @GetMapping("selectByAllPayMethodBusinessTrip")
    public Result selectByAllPayMethodBusinessTrip(){
        return businessTripService.selectByAllPayMethodBusinessTrip();
    }

    // 出差 查看当前用户未结清的账单
    @GetMapping("selectByPayMethodBusinessTripToken")
    public Result selectByPayMethodBusinessTripToken(){
        return businessTripService.selectByPayMethodBusinessTripToken();
    }

    // 出差 增加差旅
    @PostMapping("addBusinessTrip")
    public Result addBusinessTrip(@RequestBody BusinessTrip businessTrip){
        return businessTripService.addBusinessTrip(businessTrip);
    }*/

    // ~~~~~~~~~~~~日志~~~~~~~~~~~~~~~

    // 日志 查询分组和以时间排序 同时分页查询
    @GetMapping("selectLogOrderGroup")
    public Result selectLogOrderGroup(Integer page){
        return operationLogService.selectLogOrderGroup(page);
    }

    // 日志 插入日志数据
    @PostMapping("insertLog")
    public Result insertLog(@RequestBody OperationLog operationLog){
        return operationLogService.insertLog(request, operationLog);
    }

    // 日志 时间排序 查询所有
    @GetMapping("selectLog")
    public Result selectLog(){
        return operationLogService.selectLog();
    }

    // ~~~~~~~~~~~~用户~~~~~~~~~~~~~~~
    // 查询用户自己的信息
    @GetMapping("selectMyUser")
    public Result selectMyUser(){
        return operationLogService.selectMyUser();
    }

    // 通过用户id查询用户
    @GetMapping("selectUserById")
    public Result selectUserById(@RequestParam Integer id){
        return userService.selectUserById(id);
    }

    // 用户 修改个人信息
    @PostMapping("updateUserByToken")
    public Result updateUserByToken(@RequestBody Users users){
        return userService.updateUserByToken(users);
    }

    // 用户 修改密码
    @PostMapping("updatePasswordByToken")
    public Result updatePasswordByToken(@RequestParam String oldPassword, @RequestParam String newPassword){
        return userService.updatePasswordByToken(oldPassword, newPassword);
    }

    // ~~~~~~~~~~~~发票~~~~~~~~~~~~~~~
    // 发票 查询所有发票
    @GetMapping("selectAllBill")
    public Result selectAllBill(){
        return billService.selectAllBill();
    }

    // 发票 通过id查询发票
    @GetMapping("selectBillById")
    public Result selectBillById(@RequestParam Integer id){
        return billService.selectBillById(id);
    }

    // 发票 增加发票
    @PostMapping("addBill")
    public Result addBill(@RequestBody Bill bill){
        return billService.addBill(bill);
    }

    // ~~~~~~~~~~~~EXCEL~~~~~~~~~~~~~~~
    // Excel 导出测试
    @GetMapping("excelExport")
    public void excelExport(){
        excelService.excelExport();
    }

    // Excel总账导出
    @GetMapping("excelGeneralLedger")
    public void excelGeneralLedger(){
        excelService.excelGeneralLedger();
    }

    // ~~~~~~~~~~~~公司财产计算~~~~~~~~~~~~~~~
    // 计算总资产
    @GetMapping("getCompanyCost")
    public Result getCompanyCost(){
        return companyService.getCompanyCost();
    }

    // 注入资产                 只需要增加资金和发票      要去税的呀
    @PostMapping("assetInject")
    public Result assetInject(@RequestBody Project project){
        return projectService.assetInject(project);
    }

    // 借贷                     借多少， 开什么发票
    @PostMapping("loan")
    public Result loan(@RequestBody Project project){
        return projectService.loan(project);
    }

    // 财务分析
    @GetMapping("financialAnalysis")
    public Result financialAnalysis(){
        return companyService.financialAnalysis();
    }

}
